package com.tzu.utils;

import java.util.Scanner;

/**
 * 操作系统工具
 *
 */
public class OSTools {

    public static String getCpuId() {
        String cpuid = "";
        try {
            long start = System.currentTimeMillis();
            //windows命令
            String[] wincmd = new String[]{"wmic", "cpu", "get", "ProcessorId"};
            //linux命令
            String[] linuxcmd = new String[]{"dmidecode", " -t", "4", "|", "grep", "ID"};
            //系统判断
            String[] execmd = OSType.isFamilyWindows() ? wincmd : linuxcmd;
            //执行
            Process process = Runtime.getRuntime().exec(execmd);
//            process.waitFor();
//            process.getOutputStream().close();
            Scanner sc = new Scanner(process.getInputStream());
            String property = sc.next();
            String serial = sc.next();
//            System.out.println(property + ": " + serial);
//            System.out.println("time:" + (System.currentTimeMillis() - start));
            cpuid = serial;
            process.destroy();
            sc.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cpuid;
    }

    public static void main(String[] args) {
        System.out.println(getCpuId());
    }


}
